<template>
  <view class="container">
		<nav-ber :title="'发布任务详情'" :bgColor="'#f7f8ff'"></nav-ber>
		<view class="province">
			<uFrom key="keys" ref="getFrom" :itemList="itemList" :itemKeys="itemKeys" @setdata="setdataFun"></uFrom>
		<!-- 	<view class="button_str" @click="confirm">
				确认
			</view> -->
		</view>
  </view>
</template>
<script>
	import { applyById, timed_task_type, setApply } from '@/api/task.js'
  export default {
    data() {
			return {
				rules: {
					name: [
						{
							required: true,
							message: "请输入姓名",
							// 可以单个或者同时写两个触发验证方式
							trigger: ["change", "blur"],
						},
						// {
						// 	// 自定义验证函数，见上说明
						// 	validator: (rule, value, callback) => {
						// 		// 上面有说，返回true表示校验通过，返回false表示不通过
						// 		// this.$u.test.mobile()就是返回true或者false的
						// 		return this.$u.test.chinese(value);
						// 	},
						// 	message: "姓名输入不正确",
						// 	// 触发器可以同时用blur和change
						// 	trigger: ["change", "blur"],
						// },
					],
				},
				keyword: '',
				ispro: '1',
				list: ['进行中', '已完成'],
				current: 0,
				itemList: [
					{
						label: '任务名称',
						model: 'name',
						required: false,
						disabled: true,
						message: '请输入任务名称',
						type: 'input'
					},
					{
						label: '任务类型',
						model: 'typeName',
						modelName: 'type',
						required: false,
						disabled: true,
						message: '请输入任务类型',
						type: 'select',
						controls: 'select',
						keyName: 'dictLabel',
						url: 'system/dict/data/type/timed_task_type',
						value: 'dictValue',
						actions: [],
					},
					{
						label: '品种',
						model: 'drugName',
						disabled: true,
						required: false,
						message: '请输入品种',
						type: 'input'
					},
					{
						label: '省份',
						model: 'province',
						disabled: true,
						required: false,
						message: '请输入省份',
						type: 'input'
					},
					// {
					// 	label: '医院名称',
					// 	model: 'hospital',
					// 	modelName: 'hospitalList',
					// 	url: 'base/hospital/list',
					// 	mulData: 'mulData',
					// 	required: true,
					// 	message: '请输入医院名称',
					// 	type: 'mulSelect'
					// },
					// {
					// 	label: '申请数量',
					// 	model: 'applyQty',
					// 	required: true,
					// 	message: '请输入申请数量',
					// 	type: 'input',
					// 	test: 'digits',
					// 	maxlength: 10,
					// },
					{
						label: '开始时间',
						model: 'startTime',
						disabled: true,
						required: false,
						message: '请选择开始时间',
						type: 'select',
						controls: 'time',
						title: '请选择时间',
					},
					{
						label: '截止时间',
						model: 'endTime',
						disabled: true,
						required: false,
						message: '请选择截止时间',
						type: 'select',
						controls: 'time',
						title: '请选择时间',
					},
					{
						label: '申请人',
						model: 'createBy',
						disabled: true,
						required: false,
						message: '请输入申请人',
						type: 'input'
					},
					{
						label: '创建时间',
						model: 'createTime',
						disabled: true,
						required: false,
						message: '请选择创建时间',
						type: 'select',
						controls: 'time',
						title: '请选择时间',
					},
				],
				itemKeys: {
					titles: '',
					sel: ''
				}
			}
    },
		methods: {
			timed_task_typeFun() {
				
			},
			applyByIdFun(id) {
				applyById(id).then((res) => {
					timed_task_type().then((item) => {
						// res.type == '1'? ''
						res.data.typeName = item.data.filter(items => items.dictValue == res.data.type)[0].dictLabel
						res.data.hospital = '' 
						res.data.applyQty = ''
						res.data.hallId = res.data.id
						res.data.status = 0
						res.data.id = undefined
						res.data.createBy = JSON.parse(uni.getStorageSync('userInfo')).userName
						res.data.mrId = JSON.parse(uni.getStorageSync('userInfo')).userId
						this.itemKeys = res.data
					})
					
				})
			},
			setdataFun(val) {
				val.applyQty = (+val.applyQty)
				setApply(val).then((res) => {
					uni.showToast({
					  title: '申请成功',
					  icon: "none",
					  duration: 2000,
						success: () => {
							setTimeout(() => {
								uni.navigateBack({
									delta: 1,
								})
							}, 500)
						}
					})
					
				})
			},
			confirm() {
				// console.log('this.$refs.getFrom', this.$refs.getFrom.submit())
				this.$refs.getFrom.submit()
			},
			proFun(val) {
				this.ispro = val
			},
			sectionChange(index) {
				this.current = index;
			},
		},
		onShow() {
			
		},
		onLoad(option) {
			this.applyByIdFun(option.id)
		},
		mounted() {
			
		},
  }
</script>
<style lang="scss" scoped>
	.sea_pad {
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.container {
		background-color: #f7f8ff;
		// background-color: #fff;
		display: flex;
		flex-direction: column;
		height: 100vh;
		overflow: hidden;
	}
	.province {
		flex: 1;
		overflow: scroll;
		padding: 0 20rpx;
		margin-top: 20rpx;
		padding: 0 40rpx;
		box-sizing: border-box;
	}
	.button_str {
		width: 80%;
		margin: auto;
		text-align: center;
		border-radius: 100rpx;
		padding: 20rpx 10rpx;
		background-color: rgb(3, 121, 255);
		color: #fff;
		box-sizing: border-box;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
	}
</style>
